local huaiyu = fk.CreateSkill({
  name = "cc__huaiyu",
})

huaiyu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#huaiyu_choose",
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(huaiyu.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0  and #to_select:getCardIds("he") > 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = room:askToChooseCards(player,{
      target=target ,
      min=1,
      max=2,
      flag="he",
      skill_name=huaiyu.name,
    })
    room:useVirtualCard("ex_nihilo", cards, player, target, huaiyu.name)
  end,
})

huaiyu:addEffect(fk.Damaged, {
  anim_type = "masochism",
  prompt = "#huaiyu_choose",
  trigger_times = function (self, event, target, player, data)
    return data.damage
  end,
  on_use = function(self, event, target, player, data)
    if not player.dead then
      local room = player.room
      local to = room:askToChoosePlayers(player, {
        targets = room:getAlivePlayers(),
        min_num = 1,
        max_num = 1,
        prompt = "#huaiyu_choose",
        skill_name = huaiyu.name,
      })
      if #to~=0 then
        local cards = room:askToChooseCards(player,{
        target= to[1],
        min=1,
        max=2,
        flag="he",
        skill_name=huaiyu.name,
        })
        room:useVirtualCard("ex_nihilo", cards, player, to[1], huaiyu.name)
      end
      
    end
  end,
})

Fk:loadTranslationTable {
["cc__huaiyu"] = "怀玉",
[":cc__huaiyu"] = "出牌阶段限一次，或你受到１点伤害后，你可以将一名角色区域内的至多两张牌当【无中生有】对其使用。",
["$cc__huaiyu1"] = "",
["$cc__huaiyu2"] = "",
["#huaiyu_choose"] = "你可以将一名角色区域内的至多两张牌当【无中生有】对其使用。",
}

return huaiyu